/********************************
The 'this' Keyword in Practice
*/

console.log(this);                          // {}

calculateAge(1990);

function calculateAge(year) {
    console.log(2016 - year);
    console.log(this === global);          // true
}

var john = {
    name: 'John',
    yearOfBirth: 1990,
    calculateAge: function() {
        this.age = 2018 - this.yearOfBirth;
        console.log(this);

        innerFunction();    // 常规的方法调用中，this都指向global(浏览器中是window对象)

        function innerFunction() {
            console.log(this === global);       // true
        }
    }
}

john.calculateAge();

var mark = {
    name: 'Mark',
    yearOfBirth: 1991
}

console.log('--------------------------------------------');

mark.calculateAge = john.calculateAge;
mark.calculateAge();